<!--
 * @Author: your name
 * @Date: 2022-04-22 10:38:54
 * @LastEditTime: 2022-04-22 11:10:09
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /测试文档/26.html
-->
<script>
  // 图层点击事件/gis服务的点击传参
  //  clickHandler:null
  export function layerClickHandler() {
    const that = this;
    this.clickHandler = new Cesium.ScreenSpaceEventHandler(
      this.viewer.scene.canvas
    );
    this.clickHandler.setInputAction((e) => {
      let position = Cesium.Cartographic.fromCartesian(
        that.viewer.scene.pickPosition(e.position)
      );
      // 将获取到的纬度经度由弧度转为角度
      position.longitude = Cesium.Math.toDegrees(position.longitude);
      position.latitude = Cesium.Math.toDegrees(position.latitude);
      const queryPoint = { x: position.longitude, y: position.latitude };
      // const queryPoint = { x: 120.16980200000012,y: 30.0245680000001};
      const queryParam = {
        spatialRel: "esriSpatialRelIntersects", //相交
        geometryType: "esriGeometryPoint",
        geometry: JSON.stringify({
          x: queryPoint.x,
          y: queryPoint.y,
          spatialReference: { wkid: 4490 },
        }),
        where: "1=1", //1=1全部
        f: "json",
      };
      // 将当前点的坐标生成多边行圆 （引用truf.js）
      const point = turf.point([position.longitude, position.latitude])
      const buffered = turf.buffer(point, 1, { units: "kilometers" })
      const points = buffered.geometry.coordinates[0]
      // console.log(points);
      const queryParams = {
        spatialRel: "esriSpatialRelContains", //包含
        geometryType: "esriGeometryPolygon",
        geometry: JSON.stringify({
          rings: [points],
          spatialReference: { wkid: 4490 },
        }),
        where: "1=1",
        f: "json",
      };
      // 绿色矿山
      axios
        .post(
          "xxxxx/512834d664a4d3407b4c18ba3e8b3b66373945ec/ArcGIS/MapService/Catalog/SDE.R2020_DKC_LSKS.gis/query",
          qs.stringify(queryParam)
        )
        .then((res) => {
          console.log("数据------->", res);
        })
        .catch();
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }
  // 监听相机高度
  Viewer.camera.changed.addEventListener(cameraHeight);
  function cameraHeight() {
    const height = Viewer.camera.positionCartographic.height;
    // console.log("高度------>", height);
  }
  // 打开 GIS 图层服务
  // URL: xxx/512834d664a4d3407b4c18ba3e8b3b66373945ec/ArcGIS/MapService/Catalog/SDE.R2020BGDCWDGD.gis
  function openResources(URL, Name, index) {
    chaos = getChaos();
    Viewer = chaos.viewer;
    Cesium = chaos.cesium;
    const xx =
      Viewer.imageryLayers.addImageryProvider(
        new Cesium.CGCS2000MapServerImageryProvider({
          name: Name + index,
          url: URL,
          suggest: true
        })
      );
  }
  // 移除
  viewer.imageryLayers.remove(layerName)
  //  打开 MVT 图层服务
  // url: xxxx/iserver/services/map-mvt-KenZaoGengDi/restjsr/v1/vectortile/maps/%E5%9E%A6%E9%80%A0%E8%80%95%E5%9C%B0
  const xxx = Viewer.scene.addVectorTilesMap(
    {
      url: data.url,
      name: data.name
    })
    // 移除
  viewer.scene.removeVectorTilesMap(name)
</script>